package com.test.web;

import com.test.model.EbProduct;
import com.test.service.EbProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/product")
public class EbProductController {
    @Autowired
    private EbProductService ebProductService;
    @RequestMapping("/detail")
    public String detail(Model model, int epId){
        //调用service根据id查询商品信息
        EbProduct ebProduct=ebProductService.detail(epId);
        //将数据绑定model--数据
        model.addAttribute("product",ebProduct);
        //返回view--html
        return "product-view";
    }

    @RequestMapping("/add_car")
    public String addCar(int epId, HttpServletRequest request){
        //调用service将商品加入购物车
        ebProductService.addCar(epId,request);
        //绑定数据到service中，在此处不需要，因为在service已经放在session中
        //返回shopping.html页面
        return "shopping";
    }

    @RequestMapping("/pay")
    public String pay(){
        return "shopping-result";
    }
}
